# Makefile for all foreign-related libraires

srcdir = @srcdir@
builddir = @builddir@
CC = @CC@

LIBFFI_LOCAL_INCLUDE_ON = -Ilibffi/include
LIBFFI_LOCAL_INCLUDE_OFF =
CFLAGS = @CFLAGS@ @COMPFLAGS@ @PROFFLAGS@
CPPFLAGS = @PREFLAGS@
ALL_CFLAGS = $(CFLAGS) $(CPPFLAGS) @OPTIONS@ @MZOPTIONS@ \
         -I$(builddir)/.. \
         -I$(srcdir)/../include -I$(srcdir)/../src \
         -I$(srcdir)/../../rktio -I$(builddir)/../rktio \
         $(LIBFFI_LOCAL_INCLUDE_@OWN_LIBFFI@)
ARFLAGS = @ARFLAGS@
NOOP = :

# compile sub-libraries & foreign.c
all:
	$(MAKE) foreign.@LTO@
	$(MAKE) libffi_@OWN_LIBFFI@

libffi_ON:
	$(MAKE) libffi/libffi@FOREIGN_CONVENIENCE@.la

libffi_OFF:
	$(NOOP)

# just foreign.c, which will generate a stub module:
stub:
	$(MAKE) foreign.@LTO@

# Causes objects to be generated in libffi/src/
#  in inconvenience mode:
libffi/libffi@FOREIGN_CONVENIENCE@.la:
	cd libffi; $(MAKE) libffi@FOREIGN_CONVENIENCE@.la

foreign.@LTO@: $(srcdir)/foreign.c \
           $(srcdir)/../sconfig.h \
           $(srcdir)/../include/scheme.h \
           $(srcdir)/../include/schthread.h \
           $(srcdir)/../src/schemef.h \
           $(srcdir)/../src/stypes.h \
           $(srcdir)/../src/schpriv.h
	$(CC) $(ALL_CFLAGS) -c $(srcdir)/foreign.c -o foreign.@LTO@

clean:
	rm -f foreign.@LTO@
	if [ -d libffi ] ; then cd libffi ; $(MAKE) clean ; fi
